using System;
using System.Linq;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using VSSAHT.Transfer;
using VSS_AHT.DataAccess;
using VSSAHT.DataAccess;
using VSSAHT.Database;
using System.Collections.Generic;
using System.Diagnostics;

namespace VSSAHT.DataAccess
{
	public class ModelVehicleDataAccess : ModelVehicleDataAccessBase, IModelVehicleDataAccess
	{
        private ModelVehicleDTO _searchObject;
        /// <summary>
        /// Search Object Property
        /// </summary>
        public ModelVehicleDTO SearchObject
        {
            get
            {
                return _searchObject;
            }
            set
            {
                if (_searchObject != value)
                {
                    _searchObject = value;
                }
            }
        }

        #region Methods

        public IList<ModelVehicleDTO> Search()
        {
            IList<ModelVehicleDTO> collection = null;
            try
            {
                using (VSSAHTDataContext dataContext = new VSSAHTDataContext(base.ConnectionString))
                {
                    IQueryable<ModelVehicle> query = dataContext.ModelVehicles;
                    if (!String.IsNullOrEmpty(_searchObject.ModelVehicleNumber))
                    {
                        query = query.Where(e => e.ModelVehicleNumber.Contains(_searchObject.ModelVehicleNumber));
                        //hasConditions = true;
                    }
                   
                    collection = new List<ModelVehicleDTO>();
                    foreach (var item in query)
                    {
                        collection.Add(ModelVehicleMapper.ToBusinessObject(item));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return collection;
        }
        #endregion
	}
}
